using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Model;
using BLL;
using BLL.Impl;
using Common;
using System.Collections.Generic;

namespace WebUI.Driver
{
    public partial class Driver_List : BasicPage
    {
        private IDriverManger driverManager;

        private List<Model.Driver> driverList;

        protected void Page_Load(object sender, EventArgs e)
        {
            driverManager = BLLFactory.CreateDriverManger();
            driverList = driverManager.ListDriver();
            if (!IsPostBack)
            {
                Display();
            }
        }

        private void Display()
        {
            this.grvDriverList.DataSource = driverList;
            this.grvDriverList.DataKeyNames = new string[] { "PersonSN" };
            this.grvDriverList.DataBind();
        }

        protected void grvDriverList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Model.Driver driver = new Model.Driver();
            driver.PersonSN = Int32.Parse(this.grvDriverList.DataKeys[e.RowIndex].Value.ToString());
            driverManager.DelectDriver(driver);
            Display();
        }

        protected void grvDriverList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.grvDriverList.PageIndex = e.NewPageIndex;
            Display();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Model.Driver driver = new Model.Driver();
            if (!String.IsNullOrEmpty(this.txtPersonSn.Text.Trim()))
            {
                driver.PersonSN = Int32.Parse(this.txtPersonSn.Text.Trim());
            }
            if (!String.IsNullOrEmpty(this.txtPersonName.Text.Trim()))
            {
                driver.PersonName=this.txtPersonName.Text.Trim();
            }
            if (!String.IsNullOrEmpty(this.txtTel.Text.Trim()))
            {
                driver.Tel = this.txtTel.Text.Trim();
            }
            if (0 != this.ddrDriverType.SelectedIndex)
            {
                driver.DriverType=this.ddrDriverType.SelectedValue;
            }
            if (0!=this.ddrStateType.SelectedIndex)
            {
                driver.DriverState = this.ddrStateType.SelectedValue;
            }
            driverList = driverManager.SelectDriver(driver);
            Display();
        }
    }
}
